<?php

ob_start();
include 'connect/connect.php';
check_admin();
include 'class/class.phieuthu.php';

$main = file_get_contents('template/main.html');
$phieuthu = new phieuthu;
$sotien=0;
$result = mysql_query("SELECT * FROM tbl_thuphieu order by f_maphieu DESC ")
    or die(mysql_error());
if($_SESSION['user_admin'] == 2 || $_SESSION['user_admin'] == 3){
  $result = mysql_query("SELECT * FROM tbl_thuphieu where f_khoa = 2 order by f_maphieu DESC ")
    or die(mysql_error());
}
echo "<table border='1' style='border-collapse: collapse'>";
echo '<td width="60" bgcolor="#D6E0D8">Mã phiếu</td>
			<td width="75" bgcolor="#D6E0D8">Ngày tạo</td>
			<td width="50" bgcolor="#D6E0D8">Tiền học phí</td>
			<td width="60" bgcolor="#D6E0D8">Tiền giảm thu</td>
			<td width="70" bgcolor="#D6E0D8">Tiền phụ thu</td>
			<td width="80" bgcolor="#D6E0D8">Tiền thực thu</td>
			<td width="100" bgcolor="#D6E0D8">Người tạo</td>
			<td width="70px" bgcolor="#D6E0D8">Họ và tên</td>
      <td width="70" bgcolor="#D6E0D8">Ghi chú</td>
			<td width="170px" bgcolor="#D6E0D8">Comment</td>
			<td bgcolor="#D6E0D8">Trạng thái</td>
      <td bgcolor="#D6E0D8">Khóa</td>
      <td bgcolor="#D6E0D8">Giảng viên</td>
      <td bgcolor="#D6E0D8">Hoa hồng</td>
      <td bgcolor="#D6E0D8">Đính kèm</td>
      <td bgcolor="#D6E0D8">Edit</td>
      <td>In phiếu</td>';
while ($row = mysql_fetch_array($result)) {
  echo "<tr>";
  echo "<td>" . $row['f_maphieu'] . "</td>";
  echo "<td>" . $row['f_ngaytao'] . "</td>";
  echo "<td>" . number_format($row['f_tienhp']) . "</td>";
  $sotien = $sotien + $row['f_thucthu'];
  echo "<td>" . number_format($row['f_tiengt']) . "</td>";
  echo "<td>" . number_format($row['f_tiencd']) . "</td>";
  echo "<td>" . number_format($row['f_thucthu']) . "</td>";
  echo "<td>" . $row['f_nguoitao'] . "</td>";
  echo "<td>" . $row['f_hovaten'] . "</td>";
  echo "<td>" . $row['f_dkbd_ca'] . "</td>";
  $comment = mysql_query("SELECT comment FROM `comment` WHERE `mhs` = '" . $row['f_maphieu'] . "' order by `id` DESC limit 1")
      or die(mysql_error());
  $cot = mysql_fetch_array($comment);
  echo "<td>" . $cot['comment'] . "</td>";
  echo "<td>" . $phieuthu->trang_thai($row['f_trangthai']) . "</td>";
  echo "<td>" . $phieuthu->khoa($row['f_khoa']) . "</td>";
  echo "<td>" . $row['f_tengiangvien'] . "</td>";
  echo "<td>" . $row['f_hoahong'] . "</td>";
  echo "<td> <a href=" . $row['file'] . ">F</a></td>";
  echo "<td> <a href='edit.php?stt=" . $row['f_maphieu'] . "'>E</a></td>";
  echo '<td bgcolor="#D6E0D8"><a href=printer.php?id=' . $row['f_maphieu'] . ' target="_new">In</a></td>';
  echo "</tr>";
}
echo "</table>";
echo 'Tổng số tiền học phí là: ' . number_format($sotien);
echo "<p>";
echo 'Hom nay la ' . date("d-m-y");
?>
